(defun loc-(l loc-type)

  (labels ((loc (l loc-type)
  (if (atom l)
      l
  (let ((t-type (car loc-type))(t-val (cadr loc-type))(t-num (if (integerp (nth 2 loc-type)) (nth 2 loc-type) 0))(a (car l)))
    (if (atom a)
	(cond ((and (eql a 'defun)(eql (cadr l) t-val)(eql t-type 'func-define))(return-from loc- (if (= t-num 0) (setf res l)(setf res (nth t-num l)))))
	      ((and (eql a t-val)(eql t-type 'func-call))(return-from loc- (if (= t-num 0) (setf res l)(setf res (nth t-num l)))))
	      (t (loc (cdr l) loc-type)))
	(progn (loc (car l) loc-type)(loc (cdr l) loc-type)))))))
    (loc l loc-type)))

(defun _get_loc_num(i loc-type)
  (if (integerp (nth i loc-type))
      (nth i loc-type)
      0))

(defun _loc(l loc-type)
  (let ((ll l))
 (dotimes (i (length loc-type))
	(let ((t-type (nth i loc-type))(t-val (nth (1+ i) loc-type))(t-num (_get_loc_num (+ i 2) loc-type)))
	 ; (format t "ll=~a~% len= ~a i=~a t-type=~a t-val=~a t-num=~a~%" ll (length loc-type) i t-type t-val t-num)
	  (cond ((or (eql t-type 'func-define)(eql t-type 'func-call))
		 (progn (setf ll (loc- ll (list t-type t-val t-num)))
			(if (integerp (nth (+ i 2) loc-type))
			    (setf i (+ i 2))
			    (setf i (+ i 1)))))
		(t (progn (setf ll (loc- ll (list 'func-call t-type (_get_loc_num (+ i 1) loc-type))))
			  (if (integerp (nth (+ i 1) loc-type))
			      (setf i (+ i 1))))))))
 ll))
